import { AfterViewInit, Component, OnInit } from '@angular/core';
import { MatSelectionListChange } from '@angular/material/list';
import { PageEvent } from '@angular/material/paginator';
import { UserI } from 'src/app/model/user.interface';
import { AuthService } from 'src/app/public/services/auth-service/auth.service';
import { ChatService } from '../../services/chat-service/chat.service';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss'],
})
export class DashboardComponent implements OnInit ,AfterViewInit{
  rooms$ = this.chatService.getMyRooms();
  selectedRoom = null
  user:UserI = this.authService.getLoggedInUser()
  constructor(private chatService: ChatService,private authService:AuthService) {}

  ngOnInit(): void {
    this.chatService.emitPaginateRooms(10,0)
  }

  ngAfterViewInit(): void {
      this.chatService.emitPaginateRooms(10,0)
  }
  onSelectRoom(event:MatSelectionListChange){
    this.selectedRoom = event.source.selectedOptions.selected[0].value
  }
  onPaginateRooms(pageEvent:PageEvent){
    this.chatService.emitPaginateRooms(pageEvent.pageSize,pageEvent.pageIndex)
  }
}
